<div class="modal fade" id="edit-user" tabindex="-1">
    <div class="modal-dialog">
        <form id="edit_user_form" name="edit_user_form" method="post" action="/set/user/update_info">
            <input type="hidden" name="id" value=""/>
            <input type="hidden" name="status" value="0"/>
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="batch-title">修改用户信息</h4>
                </div>
                <div class="row row-inside">
                    <div class="col-sm-12">
                        <div class="form-group">
                            <div class="col-sm-3 text-right vertical-middle_text">单位全称<span class="text-important">*</span></div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" name="account" value="" placeholder="单位全称为您的登录用户名">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">

                        <div class="form-group">
                            <div class="col-sm-3 text-right vertical-middle_text">单位属性<span class="text-important">*</span></div>
                            <div class="dropdown col-sm-9 dropdown-block">
                                <a class="btn btn-default" data-toggle="dropdown"><span id="attribute_name" name="attribute_name" class="option-name">单位</span> <span
                                        class="caret"></span>
                                </a>
                                <ul class="dropdown-menu dropdown-option-menu">
                                    <li><a data-value="1" role="button">单位</a></li>
                                    <li><a data-value="2" role="button">学校</a></li>
                                    <li><a data-value="3" role="button">社区</a></li>
                                </ul>
                                <input name="attribute" class="option-value" type="hidden" value="1">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">

                        <div class="form-group">
                            <div class="col-sm-3 text-right vertical-middle_text">所属级别<span class="text-important">*</span></div>
                            <div class="col-sm-9 dropdown dropdown-block">
                                <a class="btn btn-default" data-toggle="dropdown"><span id="rank_name" name="rank_name" class="option-name">省级</span> <span
                                        class="caret"></span>
                                </a>
                                <ul class="dropdown-menu dropdown-option-menu">
                                    <li><a data-value="1" role="button">省级</a></li>
                                    <li><a data-value="2" role="button">市级</a></li>
                                    <li><a data-value="3" role="button">区级</a></li>
                                </ul>
                                <input name="rank" class="option-value" type="hidden" value="1">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <div class="col-sm-3 text-right vertical-middle_text">联系人<span class="text-important">*</span></div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" name="contact" value="">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <div class="col-sm-3 text-right vertical-middle_text">联系电话<span class="text-important">*</span></div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" name="contact_phone" value="">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <div class="col-sm-3 text-right vertical-middle_text">联系邮箱<span class="text-important">*</span></div>
                            <div class="col-sm-9">
                                <input class="form-control" type="text" name="email" value="">
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div style="text-align:center" class="vertical-middle_text">
                            (不重设密码请放空)
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <div class="col-sm-3 text-right vertical-middle_text">登录密码</div>
                            <div class="col-sm-9">
                                <input class="form-control" type="password" id="password" name="password" value="">
                            </div>
                        </div>
                    </div>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary" action-type="publish">保存</button>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        // $('[action-type="publish"][type="button"]').click(function () {
        //     $('#edit_edit_user_form').submit();
        // });

        $('[data-toggle="modal"][data-target="#edit-user"]').click(function () {
            reset_edit_user_form();
            var $this = $(this);
            var node = $this.parent().parent();
            edit_edit_user_form(node);
        });

        $("#edit_user_form").validate({
            submitHandler: function () {
                $.post($("#edit_user_form").attr("action"), $("#edit_user_form").serialize(), function (data) {
                    if (data === "0") {
                        alertify.alert("保存成功!", function () {
                            $('#edit-user').modal('hide');
                            location.reload();
                        });
                    } else {
                        alertify.alert(data);
                    }
                }).error(function (msg, url, line) {
                    alert(msg.responseText);
                });
            },
            ignore: "",
            rules: {
                account: {
                    required: true
                },
                contact: {
                    required: true
                },
                contact_phone: {
                    required: true
                },
                email: {
                    required: true
                }
            },
            messages: {
                account: {
                    required: "请填写单位全称"
                },
                contact: {
                    required: "请填写联系人"
                },
                contact_phone: {
                    required: "请填写联系电话"
                },
                email: {
                    required: "请填写联系邮箱"
                }
            }
        });
    });

    function reset_edit_user_form() {
        return;
            }

    function edit_edit_user_form(node) {
        $('#edit_user_form input[name="id"]').val(node.data('vid'));
        $('#edit_user_form input[name="status"]').val(node.data('status'));
        $('#edit_user_form input[name="account"]').val(node.data('account'));
        $('#edit_user_form input[name="contact"]').val(node.data('contact'));
        $('#edit_user_form input[name="contact_phone"]').val(node.data('contact_phone'));
        $('#edit_user_form input[name="email"]').val(node.data('email'));
        $('#edit_user_form input[name="password"]').val(node.data('password'));

        init_select($('#edit_user_form input[name="rank"]'), $('#edit_user_form span[name="rank_name"]'), node.data('rank'));
        init_select($('#edit_user_form input[name="attribute"]'), $('#edit_user_form span[name="attribute_name"]'), node.data('attribute'));


        if (node.data('status') == '1') {
            $('#edit_notice_form button[action-type="draft"]').hide();
            $('#edit_notice_form span[name="rank_name"]').parent().removeAttr('data-toggle');
            $('#edit_notice_form span[name="rank_name"]').next().hide();

            $('#edit_notice_form span[name="attribute_name"]').parent().removeAttr('data-toggle');
            $('#edit_notice_form span[name="attribute_name"]').next().hide();
        }
    }

    function init_select(ctr, ctr_name, data) {
        ctr.val(data);
        var vx = ctr.val();
//        if (vx != "") {
        ctr.prev().find('a').each(function () {
            var $this = $(this);
            if ($this.data('value') == vx) {
                ctr_name.text($this.text());
            }
        });
//        }
    }
</script>